package com.hopital5.zhangyz.service;

import com.hopital5.zhangyz.model.Label;
import com.hopital5.zhangyz.repository.LabelRepository;
import com.hopital5.zhangyz.vo.request.LabelVoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class LabelService {
    @Autowired
    LabelRepository labelRepository;

    public Label save(LabelVoRequest labelVoRequest) {
        Label label = Label.builder().name(labelVoRequest.getName()).build();
        return labelRepository.save(label);
    }

    @Transactional
    public Label update(LabelVoRequest labelVoRequest) {
        Label label = labelRepository.findOne(labelVoRequest.getLabelId());
        label.setName(labelVoRequest.getName());
        return label;
    }

    public Label findOne(Long id) {
        return labelRepository.findOne(id);
    }

    public void delete(Long id) {
        labelRepository.delete(id);
    }

    public void delete(Label label) {
        labelRepository.delete(label);
    }
}

